ENV['OSMLIBX_XML_PARSER']='usr/lib/ruby/1.8/xml/libxml.rb'


#require '/usr/local/lib/site_ruby/rgl/base.rb'
require '/usr/local/lib/site_ruby/rgl/adjacency.rb'
require '/usr/local/lib/site_ruby/rgl/dot.rb'
#require '/usr/local/lib/site_ruby/rgl/bidirectional.rb'
#require '/usr/local/lib/site_ruby/rgl/traversal.rb'
#require '/usr/local/lib/site_ruby/rgl/mutable.rb'

require 'yaml'
require '/usr/lib/ruby/1.8/pp.rb'
require '/var/lib/gems/1.8/gems/osmlib-base-0.1.4/lib/OSM/Database.rb'
require '/var/lib/gems/1.8/gems/osmlib-base-0.1.4/lib/OSM/objects.rb'
require '/var/lib/gems/1.8/gems/osmlib-base-0.1.4/lib/OSM/StreamParser.rb'
require '/var/lib/gems/1.8/gems/osmlib-base-0.1.4/lib/OSM/StreamParser/Libxml.rb'
require '/var/lib/gems/1.8/gems/osmlib-base-0.1.4/lib/OSM/API.rb'


thegraph = RGL::DirectedAdjacencyGraph.new

db = OSM::Database.new

parser = OSM::StreamParser.new(:filename => 'smallmap2.osm', :db => db)

parser.parse

db.ways.values.each do |way|

    firsttime = true
    way.node_objects.each do |node|
        #data = node.id
        #data << way.name
        data = node.id.to_s() if node
        data << way.name if way.name 
        if firsttime
            thegraph.add_vertex(data)
            firsttime = false
            next
        end

        idx = way.node_objects.index(node)
        childindex = idx -1
        
        puts 'the child index'
        puts way.name if way.name
        puts way.node_objects[childindex].id
        puts way.node_objects[childindex]
        puts 'the node id'
        puts node.id
        puts "======================="
        
        thegraph.add_vertex(data)
        thegraph.add_edge(data, way.node_objects[childindex].id)
        way.node_objects.shift()
    end
end
thegraph.write_to_graphic_file('jpg')
